package fileExercise;

import java.io.File;

/**
 * @classname:filedemo
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/15 17:11
 * @version: 0.1
 * @since:1.8
 */
public class filedemo {
    public static void main(String[] args) {
//        demo1();
//        demo2();
        demo3();
    }

    private static void demo3() {
        //自动创建文件或者目录
//        File file = new File("day16/src/abc.txt");
//        if(!file.exists()){
//            try {
//                boolean newFile = file.createNewFile();
//                System.out.println(newFile);
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//
//        file.delete();

//        File file = new File("day16/das");
//        try {
//            file.createNewFile();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        File file = new File("day6/dasds/dsad");
        boolean mkdirs = file.mkdirs();
        System.out.println(mkdirs);
        file.delete();


    }

    private static void demo2() {
        File directory = new File("day16/src");
        directory = new File("day16","src");
        System.out.println(directory.getName());
        System.out.println(directory.getPath());
        System.out.println(directory.getAbsolutePath());
        System.out.println(directory.getParent());
        System.out.println(directory.exists());
        System.out.println(directory.isDirectory());
    }

    private static void demo1() {
        String filePath = "day16\\src\\b.txt";
        File file = new File(filePath);
//        System.out.println(file.getName());
//        System.out.println(file.getPath());
//        System.out.println(file.getAbsolutePath());
//        System.out.println(file.length());
//        System.out.println(file.lastModified());
//        System.out.println(new Date(file.lastModified()));

        //删除文件
//        boolean delete = file.delete();
//        System.out.println(delete);
        //更改名字
        System.out.println(file.renameTo(new File("day16", "c.txt")));
    }
}
